home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kompon / d123456 / CHEMPLOT.ZIP / TPlot / TChart Demo / TChartNormal1.pas < prev   
Pascal/Delphi Source File  |  2001-07-19  |  8KB  |  282 lines

  1. unit TChartNormal1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ImgList, Menus, Grids, ExtCtrls, StdCtrls,
  8.   Buttons, ActnList, ToolWin, ComCtrls, 
  9.  
  10.   VEdit, NEdit,
  11.   Plot, Plotdefs, PlotMenu, PlotImageList, Data, TeeProcs, TeEngine, Chart,
  12.   Series;
  13.  
  14. type
  15.   TMainForm = class(TForm)
  16.     Panel1: TPanel;
  17.     StringGrid1: TStringGrid;
  18.     MinNEdit: TNEdit;
  19.     Label1: TLabel;
  20.     Label2: TLabel;
  21.     MaxNEdit: TNEdit;
  22.     Label3: TLabel;
  23.     StepSizeNEdit: TNEdit;
  24.     Label4: TLabel;
  25.     MeanNEdit: TNEdit;
  26.     Label5: TLabel;
  27.     StdDevNEdit: TNEdit;
  28.     GoBitBtn: TBitBtn;
  29.     GoCrazyBitBtn: TBitBtn;
  30.     CrazyTimer: TTimer;
  31.     ClearAllBitBtn: TBitBtn;
  32.     NoisyBitBtn: TBitBtn;
  33.     TraceBitBtn: TBitBtn;
  34.     TypeBitBtn: TBitBtn;
  35.     Chart1: TChart;
  36.     StatusBar1: TStatusBar;
  37.     Series1: TFastLineSeries;
  38.     procedure ClearAllBitBtnClick(Sender: TObject);
  39.     procedure GoBitBtnClick(Sender: TObject);
  40.     procedure FormCreate(Sender: TObject);
  41.     procedure PlotMenu1ExitMenuItemClick(Sender: TObject);
  42.     procedure NoisyBitBtnClick(Sender: TObject);
  43.     procedure GoCrazyBitBtnClick(Sender: TObject);
  44.     procedure CrazyTimerTimer(Sender: TObject);
  45.     procedure Plot1FileOpen(Sender: TObject; TheFile: String);
  46.     procedure TraceBitBtnClick(Sender: TObject);
  47.     procedure TypeBitBtnClick(Sender: TObject);
  48.   private
  49.     //Chart1: TPlot;
  50.     //PlotMenu1: TPlotMenu;
  51.     Revolutions,
  52.     StartWidth,
  53.     StartHeight: Integer;
  54.     Angle,
  55.     AngleInc: Single;
  56.     StartTime: TDateTime;
  57.   public
  58.     { Public declarations }
  59.   end;
  60.  
  61. var
  62.   MainForm: TMainForm;
  63.  
  64. implementation
  65.  
  66. {$R *.DFM}
  67.  
  68. const
  69.   RADIUS = 50.0;
  70.   MYCAPTION = 'TChart demo for Delphi';
  71.  
  72. procedure TMainForm.FormCreate(Sender: TObject);
  73. {var
  74.   PlotImageList : TPlotImageList;}
  75. begin
  76.   //Chart1 := TPlot.Create(Self);
  77.   Chart1.Parent := MainForm;
  78.   Chart1.Align := alClient;
  79.   {Chart1.PlotType := ptXY;
  80.   Chart1.NoSeries := 2;
  81.   Chart1.MakeDummyData(20);}
  82.   //PlotMenu1.Plot := Chart1;
  83.   StringGrid1.Cells[0, 0] := 'Test:';
  84.   StringGrid1.Cells[0, 1] := 'Score:';
  85.   StringGrid1.ColWidths[0] := 60;
  86.   //PlotImageList := TPlotImageList.Create(Self);
  87.   //PlotImageList.Free;
  88.   //GoBitBtnClick(Sender);
  89.   //PlotActionList1.Plot := Chart1;
  90. end;
  91.  
  92. procedure TMainForm.ClearAllBitBtnClick(Sender: TObject);
  93. var
  94.   i: Integer;
  95. begin
  96.   for i := 0 to Chart1.SeriesList.Count-1 do
  97.   begin
  98.     Chart1.Series[i].Clear;
  99.   end;
  100.  
  101.   for i := 1 to StringGrid1.ColCount-1 do
  102.   begin
  103.     StringGrid1.Cells[i, 0] := '';
  104.     StringGrid1.Cells[i, 1] := '';
  105.   end;
  106. end;
  107.  
  108. procedure TMainForm.GoBitBtnClick(Sender: TObject);
  109. var
  110.   X, Y: Single;
  111.   Mean: Single;
  112.   StdDev: Single;
  113.   Min: Single;
  114.   Max: Single;
  115.   StepSize: Single;
  116.   TheSeries: Integer;
  117.   TheScore: Single;
  118.   i: Integer;
  119.   FStartTime:          Int64; {TLargeInteger;}
  120.   FFinishTime:         Int64;
  121.   FFrequency:          Int64;
  122.   ElapsedTime: Double;
  123. begin
  124.   Screen.Cursor := crHourGlass;
  125.  
  126.   for i := 0 to Chart1.SeriesList.Count-1 do
  127.   begin
  128.     Chart1.Series[i].Clear;
  129.   end;
  130.  
  131.   Mean := MeanNEdit.AsReal;
  132.   StdDev := StdDevNEdit.AsReal;
  133.   Min := MinNEdit.AsReal;
  134.   Max := MaxNEdit.AsReal;
  135.   StepSize := StepSizeNEdit.AsReal;
  136.  
  137. {Set the axes:}
  138.   Chart1.BottomAxis.Maximum := Max;
  139.   Chart1.BottomAxis.Minimum := Min;
  140.   Chart1.LeftAxis.Minimum := 0;
  141.   //Chart1.LeftAxis.Intercept := 0;
  142.  
  143.   X := Min;
  144.   while (X <= Max) do
  145.   begin
  146.     Y := Exp(-Sqr((X-Mean)/(2*StdDev))) /
  147.       Sqrt(2*Pi*StdDev);
  148. {Don't fire any events, and don't adjust axes:}
  149.     Chart1.SeriesList[0].AddXY(X, Y);
  150.     X := X + StepSize;
  151.   end;
  152.  
  153.   {Chart1.YAxis.Min := Chart1.Series[0].YMin;}
  154.   //Chart1.LeftAxis.Maximum := Chart1.Series[0].YMax;
  155.  
  156.   {for i := 1 to StringGrid1.ColCount-1 do
  157.   begin
  158.     if (Length(StringGrid1.Cells[i, 0]) > 0) then
  159.     begin
  160.       if (Length(StringGrid1.Cells[i, 1]) > 0) then
  161.       begin
  162.         try
  163.           TheScore := StrToFloat(StringGrid1.Cells[i, 1]);
  164.           TheSeries := Chart1.Add(-1);
  165.           Chart1[TheSeries].Name := StringGrid1.Cells[i, 0];
  166.           Chart1[TheSeries].AddPoint(TheScore, Chart1.YAxis.Min, TRUE, TRUE);
  167.           Chart1[TheSeries].AddPoint(TheScore, Chart1.YAxis.Max, TRUE, TRUE);
  168.           Chart1[TheSeries].Visible := TRUE;
  169.           Chart1[TheSeries].Symbol := TSymbol(i mod (1+Ord(sDownTriangle)));
  170.         finally
  171.         end;
  172.       end;
  173.     end;
  174.   end;}
  175.   Screen.Cursor := crDefault;
  176.   Self.Caption := Format(MYCAPTION + ' - %d points', [Chart1.Series[0].Count]);
  177. end;
  178.  
  179. procedure TMainForm.PlotMenu1ExitMenuItemClick(Sender: TObject);
  180. begin
  181.   Close;
  182. end;
  183.  
  184. procedure TMainForm.NoisyBitBtnClick(Sender: TObject);
  185. begin
  186.   //Chart1.MakeDummyData(100);
  187. end;
  188.  
  189. procedure TMainForm.GoCrazyBitBtnClick(Sender: TObject);
  190. begin
  191. {We can't use the new method in "Normal", of resizing after a Paint operation:
  192.  TChart just lock up after about 10 redraws (using OnAfterDraw).
  193.  It doesn't matter anyway - TChart is slower than the Winnt timer (20 ms).}
  194.   if (CrazyTimer.Enabled) then
  195.   begin
  196.     CrazyTimer.Enabled := FALSE;
  197.     GoCrazyBitBtn.Caption := 'Go Crazy';
  198.     TraceBitBtn.Enabled := TRUE;
  199.   end
  200.   else
  201.   begin
  202.     Revolutions := 0;
  203.     StartWidth := Width;
  204.     StartHeight := Height;
  205.     StartTime := Now;
  206.     Angle := 0;
  207.     AngleInc := 4 * Pi / 180;
  208.     GoCrazyBitBtn.Caption := 'Enough !';
  209.     CrazyTimer.Enabled := TRUE;
  210.     TraceBitBtn.Enabled := FALSE;
  211.   end;
  212. end;
  213.  
  214. procedure TMainForm.CrazyTimerTimer(Sender: TObject);
  215. var
  216.   fpm: Single;
  217.   ElapsedTime: TDateTime;
  218. begin
  219.   Width := StartWidth + Round(RADIUS * Sin(Angle));
  220.   Height := StartHeight + Round(RADIUS * Cos(Angle));
  221.   Angle := Angle + AngleInc;
  222.   Inc(Revolutions);
  223.   ElapsedTime := Now - StartTime;
  224.   fpm := Revolutions / ((24 * 3600)*ElapsedTime);
  225.   StatusBar1.SimpleText := Format(
  226.     '%d frames, %8.2f frames per second',
  227.     [Revolutions, fpm]);
  228. end;
  229.  
  230. procedure TMainForm.Plot1FileOpen(Sender: TObject; TheFile: String);
  231. var
  232.   TheTitle: String;
  233. begin
  234.   TheTitle := ExtractFileName(Application.ExeName);
  235.   TheTitle := Copy(TheTitle, 1, Length(TheTitle)-4);
  236.   TheTitle := TheTitle + ' - ' + ExtractFileName(TheFile);
  237.   Application.Title := TheTitle;
  238.   MainForm.Caption := TheTitle;
  239. end;
  240.  
  241. procedure TMainForm.TraceBitBtnClick(Sender: TObject);
  242. begin
  243.   //Chart1.Trace;
  244. end;
  245.  
  246. procedure TMainForm.TypeBitBtnClick(Sender: TObject);
  247. var
  248.  ThePlotType: Integer;
  249. begin
  250.   {ThePlotType := Ord(Chart1.PlotType);
  251.   ThePlotType := (ThePlotType+1) mod (Ord(High(TPlotType))+1);
  252.   Chart1.SeriesList.ClearSeries;
  253.   Chart1.PlotType := TPlotType(ThePlotType);
  254.   case Chart1.PlotType of
  255.     ptXY: Chart1.MakeDummyData(100);
  256.     ptError, ptMultiple: Chart1.MakeDummyData(20);
  257.     ptColumn, ptStack, ptNormStack: Chart1.MakeDummyData(10);
  258.     ptPie: Chart1.MakeDummyData(10);
  259.     ptPolar:
  260.       begin
  261.         Chart1.XAxis.Min := -10;
  262.         Chart1.XAxis.Max := 10;
  263.         Chart1.YAxis.Min := -10;
  264.         Chart1.YAxis.Max := 10;
  265.         Chart1.MakeDummyData(20);
  266.       end;
  267.     pt3DWire, pt3DSurface:
  268.       begin
  269.         Chart1.XAxis.Min := 0;
  270.         Chart1.XAxis.Max := 10;
  271.         Chart1.YAxis.Min := 0;
  272.         Chart1.YAxis.Max := 10;
  273.         Chart1.MakeDummyData(20);
  274.         Chart1.NoSeries := 8;
  275.         Chart1.MakeDummyData(10);
  276.       end;
  277.   else ;
  278.   end;}
  279. end;
  280.  
  281. end.
  282.